home *** CD-ROM | disk | FTP | other *** search
/ Light ROM 3 / Light ROM 3 - Disc 2.iso / programs / amiga / misc / terrain3.lzh / enq.c < prev    next >
C/C++ Source or Header  |  1987-08-23  |  8KB  |  230 lines

  1. /* *************************************************************************
  2.  
  3.        The modified code in the appended section was extracted from
  4.  
  5.                      MENUS, REQUESTORS, AND GADGETS 
  6.                                   BY 
  7.                             John T. Draper 
  8.                  A service from the Programmers Network 
  9.                        on the WELL in Sausalito. 
  10.                      Article 408@well and 409@well
  11.                            December 31, 1985
  12.  
  13.   Permission to post this on other networks is granted provided the 
  14. source of this information is included.   The programmers network is 
  15. a non-profit network exchange of programming information.   For more 
  16. information,  mail your requests to: 
  17.  
  18. WELL: crunch orsomewellprogrammerwhosequipmenthasnotbeenseized
  19. BIX:  crunch orsomewellprogrammerwhosequipmenthasnotbeenseized
  20. USENET: ihnp4!ptsfa!well!crunch orsomewellprogrammerwhosequipmenthasnotbeenseized
  21. DELPHI: crunch orsomewellprogrammerwhosequipmenthasnotbeenseized
  22.  
  23.  ************************************************************************* */
  24.  
  25. /*
  26.  * Hacked to make autoEnquirer, a positionable position-tracking requester
  27.  *
  28.  *   Date:        July 11, 1987
  29.  *   Barbarian:   Howard Hull
  30.  *   Implements:  custom requester code from John Draper's gadget tutorial
  31.  *                + blood, sweat, tears, & additions to the explative list...
  32.  */
  33.  
  34. /* **********************************************************
  35.  *
  36.  * ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  37.  * :: When you're a tiger trainer, it's a bad deal when  ::
  38.  * :: the tiger gets your attention by putting a paw in  ::
  39.  * :: your face.  This is not only because tiger paws    ::
  40.  * :: don't smell very good  - it's also because you'll  ::
  41.  * :: shortly begin to wonder what the rest of the tiger ::
  42.  * :: is up to.  With that paw in your face, you can't   ::
  43.  * :: determine what you need to know to decide on what  ::
  44.  * :: ought to be done next.  With tigers, it's much the ::
  45.  * :: same as it is with anything else:  As Will Rogers  ::
  46.  * :: once said, "It ain't what we know that gets us in  ::
  47.  * :: trouble.  It's what we know that ain't so..."      ::
  48.  * ::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  49.  *
  50.  *
  51.  * I wrote this thing up because I got tired of moving the requester
  52.  * out of the way so I could see what was going on, and that in turn
  53.  * so that I could then decide what to do with the requester.  As all
  54.  * of you by now know, and as is evident in the net programs, if you
  55.  * make an AutoRequest, you get a requester at 0,0 with no programmable
  56.  * options to reposition it anywhere that you'd rather it be put. (Correct?)
  57.  *
  58.  * Given that the Gadget Editor Boys have not yet released their product
  59.  * (I think they are waiting for John Draper's life to get a little less
  60.  * complicated) I thought I'd put this out in the mean time.  As I'm very
  61.  * much a C programming novice, I'm putting this up for some presumably
  62.  * critical guidance.  Rather than being an example of proper code, I'm
  63.  * certain it contains a number of spectacular boo boos - maybe including
  64.  * some assumptions that would make the whole program completely unnecessary.
  65.  * Just as John said, requesters are a pain in the *ss.  But without a
  66.  * gadget editor, this is the sort of thing that has to be done...
  67.  *
  68.  */
  69.  
  70. #include "atv3d.h"
  71.  
  72. extern short wleftedge;     /* These are the variables in which we     */
  73. extern short wtopedge;      /* put the first received positions.       */
  74.  
  75. extern struct IntuiText negtext; /* Let the user keep the button names in */
  76. extern struct IntuiText postext; /*  in his stuff, like for AutoRequest */
  77.  
  78. struct Requester req;            /* custom requester structure */ 
  79.  
  80. /*
  81.  * Above is an instance of the (empty) Requester stucture.  It contains a
  82.  * pointer to the host window through the RWindow structure.  (The empty
  83.  * Requester structure was defined just above this comment.  It is not
  84.  * declared, since it gets wiped clean by the InitRequester() call in the
  85.  * user's program.  That call could be moved into this section if the user
  86.  * didn't have to follow through by initializing the structure before it
  87.  * can be used.
  88.  */
  89.  
  90. /*
  91.  * In the RWindow structure containing the window's LeftEdge - TopEdge
  92.  * definition, we wish to keep track of the requester position by means
  93.  * of these two numbers once they are initialized.  This structure is
  94.  * housed in the user's section.
  95.  */
  96.  
  97. short autoEnquire();    /* the enquirer subroutine is in this section */
  98.  
  99. /***************************************************************************
  100. *              I M P O R T A N T         C O N S T A N T S
  101. ***************************************************************************/
  102.  
  103. #define NL 0
  104.  
  105. #define REDP 3
  106. #define BLKP 2
  107. #define WHTP 1
  108. #define BLUP 0
  109.  
  110. /***************************************************************************
  111.                CUSTOM REQUEST WITH TEXT, BORDERS, AND GADGETS
  112. ***************************************************************************/
  113.  
  114. /* Border for buttons */
  115. SHORT Pairs[] = {
  116.  0, 0,            /* Coordinates relative to button position definition */
  117.  43, 0,
  118.  43, 12,
  119.  0, 12,
  120.  0,  0
  121. };
  122.  
  123. #define NUM_PAIRS 5    /* 5 pairs make a rectangle, start and stop incl */
  124. struct Border butt_border = {
  125.  -1,  -1,
  126.  BLUP, 0, JAM1,
  127.  NUM_PAIRS,
  128.  (SHORT *) Pairs,
  129.  NULL
  130. };
  131.  
  132. /* FALSE BUTTON */
  133. #define ONE_BUTT 1      /** GadgetID used to identify the action ***/
  134. struct Gadget offgad = {
  135.   NULL,
  136.   7, 42,                  /* LeftEdge, TopEdge     */
  137.   42, 11,                 /* Width,  Height        */
  138.   GADGHCOMP,              /* Flag                  */
  139.   RELVERIFY | ENDGADGET,  /* Activation            */
  140.   BOOLGADGET | REQGADGET, /* GadgetType            */
  141.   (APTR)&butt_border,     /* GadgetRender - Border */
  142.   NULL,                   /* SelectRender          */
  143.   &negtext,               /* "OK" text             */
  144.   NL, NL, ONE_BUTT, NL    /* Mut Excl, Spec Info,  */
  145.  
  146. };
  147.  
  148. /* TRUE BUTTON */
  149. #define TWO_BUTT 2
  150. struct Gadget ongad = {
  151.   &offgad,
  152.   7, 22,                  /* LeftEdge, TopEdge     */
  153.   42, 11,                 /* Width,  Height        */
  154.   GADGHCOMP,              /* Flag                  */
  155.   RELVERIFY | GADGIMMEDIATE,   /* Activation       */
  156.   BOOLGADGET | REQGADGET, /* GadgetType            */
  157.   (APTR)&butt_border,     /* GadgetRender - Border */
  158.   NULL,                   /* SelectRender          */
  159.   &postext,               /* "OK" text             */
  160.   NL, NL, TWO_BUTT, NL    /* Mut Excl, Spec Info,  */
  161. };
  162.  
  163.  
  164. /* Outside Border of Requester */
  165. SHORT ReqPairs[] = {
  166.  3, 3,        /* Coordinates relative to requester sheet top left corner */
  167.  53, 3,
  168.  53, 57,
  169.  3, 57,
  170.  3, 3
  171. };
  172.  
  173. struct Border out_border = {
  174.  -1, -1,
  175.  BLKP, 0, JAM1,
  176.  NUM_PAIRS,
  177.  (SHORT *) ReqPairs,
  178.  NULL
  179. };
  180.  
  181. /***************************************************************************
  182.                    D O   C U S T O M    R E Q U E S T
  183. ***************************************************************************/
  184.  
  185. /*
  186.  * Just as Enquiring minds want to know, Enquiring eyes want to see...
  187.  */
  188.  
  189. autoEnquire()
  190.  
  191.     short looping = TRUE;
  192.     short response = FALSE;
  193.     struct IntuiMessage *mes;
  194.     struct Gadget *gad;           /* Gadget chosen */
  195.     unsigned long class; 
  196.  
  197.     while (looping) 
  198.         { 
  199.         if ((mes = (struct IntuiMessage *)GetMsg(RWindow->UserPort)) == 0L)
  200.             { 
  201.             (VOID) Wait(1L<<RWindow->UserPort->mp_SigBit); 
  202.             continue; 
  203.         } 
  204.         class = mes->Class; 
  205.         gad = (struct Gadget *)mes->IAddress; 
  206.         (VOID) ReplyMsg(mes); 
  207.         if (class == REQCLEAR)
  208.             looping = FALSE; 
  209.         if (class == GADGETDOWN)
  210.             { 
  211.             switch (gad->GadgetID)
  212.                 { 
  213.                 case TWO_BUTT:  response = (short)TWO_BUTT-1;
  214.                                  EndRequest(&req, RWindow);
  215.                                  break; 
  216.                 case ONE_BUTT:  response = (short)ONE_BUTT-1;
  217.                                  EndRequest(&req, RWindow);
  218.                                  break; 
  219.  
  220.                 /* As you can see, adding more buttons would be easy */
  221.             } 
  222.         } 
  223.     } 
  224.     wleftedge = RWindow->LeftEdge;    /* This is where we track position  */
  225.     wtopedge = RWindow->TopEdge;      /* of the requester if it was moved */
  226. return (response);
  227.  
  228.